
const express = require('express');
const router = express.Router();
const todoList = require('../utils');


//统一处理路由

router.get('/todo', (req, res) => {
    todoList.find((err, data) => {
        if (err) {
            return res.json({ code: 403, message: '失败' })
        }
        res.json({ code: 200, message: 'ok', data: data })
    })
})
router.post('/todo/add', (req, res) => {
    todoList.save(req.body, (err, data) => {
        if (err) {
            return res.json({ code: 403, message: '失败' })
        }
        res.json({ code: 200, message: 'ok', data: data })
    })
})
router.post('/todo/delete', (req, res) => {
    todoList.deleteById(req.body.id, (err, data) => {
        if (err) {
            return res.json({ code: 403, message: '失败' })
        }
        res.json({ code: 200, message: 'ok', data: data })
    })

})

router.post('/todo/edit', (req, res) => {
    todoList.updataById(req.body.id, (err, data) => {
        if (err) {
            return res.json({ code: 403, message: '失败' })
        }
        res.json({ code: 200, message: 'ok', data: data })
    })
})
module.exports = router